import { MySeriveProvider } from './../../../providers/my-serive/my-serive';
import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { NAME } from './be-evaluated.model';
import { ɵa } from 'ionic3-index-list';
/**
 * Generated class for the BeEvaluatedPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
 
@IonicPage()
@Component({
  selector: 'page-be-evaluated',
  templateUrl: 'be-evaluated.html'
})
export class BeEvaluatedPage {
  usercode;
  evaluatingcode;
  showlist = [];
  showlist1 = [];
  avatars = [];
  nameWithAvatar = [];

  NAME = new NAME();
  nameA = [];
  nameB = [];
  nameC = [];
  nameD = [];
  nameE = [];
  nameF = [];
  nameG = [];
  nameH = [];
  nameI = [];
  nameJ = [];
  nameK = [];
  nameL = [];
  nameM = [];
  nameN = [];
  nameO = [];
  nameP = [];
  nameQ = [];
  nameR = [];
  nameS = [];
  nameT = [];
  nameU = [];
  nameV = [];
  nameW = [];
  nameX = [];
  nameY = [];
  nameZ = [];

  nameDatas = [[], [],[],[],[],[],[],[],[],[],[],[],[],[], [],[],[],[],[],[],[],[],[],[],[],[]];

  indexs = new NAME().indexs;
  n;
  sections: any[];

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public mySerive: MySeriveProvider,
    public cdRef: ChangeDetectorRef
  ) {
    this.usercode = this.navParams.get('usercode');
    this.evaluatingcode = this.navParams.get('evaluatingcode');
  }

  ionViewDidLoad() {
    const evaluating = {
      usercode: this.usercode,
      evaluatingcode: this.evaluatingcode
    };
    this.mySerive.getSorce(evaluating).subscribe(data => {
      
      for (const key in data) {
        this.showlist.push(JSON.parse(data[key]['SORCE']));
        this.nameWithAvatar.push(JSON.parse(data[key]['USER']));
      }

      for (const key in this.nameWithAvatar) {
        // 给名字排序
        this.showlist1.push(`${this.nameWithAvatar[key]['realname']} ${this.nameWithAvatar[key]['avatar']}`);
        this.showlist1.sort((param1, param2) => {
          return param1.localeCompare(param2, 'zh');
        });
      } 
      // 名字排序
      this.n = ['nameA', 'nameB', 'nameC', 'nameD', 'nameE', 'nameF', 'nameG', 'nameH', 'nameI', 'nameJ',
      'nameK', 'nameL', 'nameM', 'nameN', 'nameO', 'nameP', 'nameQ', 'nameR', 'nameS',
      'nameT','nameU', 'nameV', 'nameW', 'nameX', 'nameY', 'nameZ']; 
     
      for (const key in this.showlist1) { 
          for(let i of this.n){   
            if (this.NAME[i].indexOf(this.showlist1[key].substr(0, 1)) > 0) {
              this[i].push(this.showlist1[key]);
              break;
            }  
          } 
       }

       //检索插件节点的渲染在请求数据渲染之前 所有请求完成之后需要调用一次节点的样式重新获取 
       ɵa.prototype.ngAfterViewChecked(); 
      
        this.n.forEach((item, index) => {
          this.nameDatas[index] = this[item];
        });
      
    });
  }
  sorce(section) {
    var section = section.split(" ")[0];
    let user;
    let info;
    let usercode;
    
    for (const key in this.nameWithAvatar) {
      if (this.nameWithAvatar[key]['realname'] === section) {
        user = this.nameWithAvatar[key];
        usercode = user['usercode'];
      }
    }
    
    for (const key in this.showlist) {
      if (this.showlist[key]['usercode'] === usercode) {
        info = this.showlist[key]
      }
    }
    
    this.navCtrl.push('AllSorcePage', {
      user: user,
      info: info,
    });
  }
}
